const api = require('../../utils/api.js');
const app = getApp();

Page({
  data: {
    article_list: [],
    abnorData: {
      imgSrc: app.imgUrl + 'abnor-19.png',
      text: '暂无内容',
    },
    useTabbar: !(app.tabbarindex === 0 && app.siteInfo.tabbar_type === '1'),
    imgUrl: app.imgUrl,
  },

  onLoad(options) {
    let that = this;
    let opts = options || {};
    let id = Number(opts.id) || 2;
    app.pageOnLoad(that);
    that.setData({ 
      opts,
      useTabbar: that.data.useTabbar && app.getTabBarStatus(),
    });
    if (id === 1) {
      wx.setNavigationBarTitle({
        title: '关于我们',
      });
    } else if (id === 2) {
      wx.setNavigationBarTitle({
        title: '服务中心',
      });
    } else {
      wx.setNavigationBarTitle({
        title: '文章列表',
      });
    }
    wx.showLoading({
      title: '正在加载...',
      mask: true,
    });
    app.ws_micro_shoprequest({
      url: api.default.article_list,
      data: {
        cat_id: opts.id || 2,
      },
      success: function(res) {
        wx.hideLoading();
        that.setData({
          article_list: res.data.list,
        });
      },
    });
  },

  onNavigate(e) {
    let param = e.currentTarget.dataset;
    app.ws_micro_shop_navigate(param);
  },

  collectFormId(e) {
    app.collectFormId(e);
  },
});
